package study.singleton;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContainorSingleton {

    private ContainorSingleton(){}

    private static Map<String,Object> map = new ConcurrentHashMap<String,Object>();

    public  static Object getInstance(String className){
        synchronized(ContainorSingleton.class){

            if(map.containsKey(className)){
              return  map.get(className);
            }else{
                Object obj = null;
                try {
                    obj = Class.forName(className).newInstance();
                    map.put(className,obj);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return  obj;
            }

        }
    }
}
